package com.lcz.manage.util.event.publisher.factory;

import java.util.Map;

import org.springframework.stereotype.Component;

import com.google.common.collect.Maps;
import com.lcz.manage.util.event.publisher.EventPublisher;

/**
 * @author xingyongjiang@yunrong.cn
 * @version V3.0
 * @since 2021/4/19 12:45
 */

@Component
public class EventPublisherFactory {

    private static Map<String, EventPublisher> PUBLISHER_MAP = Maps.newConcurrentMap();

    /**
     * 注册发送器
     *
     * @param type
     * @param eventPublisher
     */
    public void register(String type, EventPublisher eventPublisher) {
        PUBLISHER_MAP.putIfAbsent(type, eventPublisher);
    }

    /**
     * 获取发送器
     *
     * @param type
     * @return
     */
    public EventPublisher getEventPublisher(String type) {
        return PUBLISHER_MAP.get(type);
    }
}
